using System;
using System.Collections.Generic;
using Dict.DataModel;

namespace Dict.Dao
{
    public class TableItemDao:DaoBase<TableItem>
    {
        public override void AddPrimaryIndex(TableItem model)
        {
            cachePrimary[model.itemId.ToString()] = model;
        }

        public override string GetFileName()
        {
            return "TableItem.txt";
        }

        protected override TableItem ParseRowData(string[] rowData)
        {
            TableItem data = new TableItem();
			data.itemId = rowData [0];
			data.name = rowData [1];

            if (string.IsNullOrEmpty(rowData[2]))
            {
                data.star = 0;
            }
            else
            {
                data.star = int.Parse(rowData[2]);
            }

            if (string.IsNullOrEmpty(rowData[3]))
            {
                data.energy = 0;
            }
            else
            {
                data.energy = int.Parse(rowData[3]);
            }

            if (string.IsNullOrEmpty(rowData[4]))
            {
                data.stamina = 0;
            }
            else
            {
                data.stamina = int.Parse(rowData[4]);
            }

            if (string.IsNullOrEmpty(rowData[5]))
            {
                data.coin = 0;
            }
            else
            {
                data.coin = int.Parse(rowData[5]);
            }

            if (string.IsNullOrEmpty(rowData[6]))
            {
                data.diamond = 0;
            }
            else
            {
                data.diamond = int.Parse(rowData[6]);
            }

            if (string.IsNullOrEmpty(rowData[7]))
            {
                data.exp = 0;
            }
            else
            {
                data.exp = int.Parse(rowData[7]);
            }

            if (string.IsNullOrEmpty(rowData[8]))
            {
                data.category = 0;
            }
            else
            {
                data.category = int.Parse(rowData[8]);
            }

            if (string.IsNullOrEmpty(rowData[9]))
            {
                data.nature = 0;
            }
            else
            {
                data.nature = int.Parse(rowData[9]);
            }

            if (string.IsNullOrEmpty(rowData[10]))
            {
                data.selloutPrice = 0;
            }
            else
            {
                data.selloutPrice = int.Parse(rowData[10]);
            }
			data.icon = rowData [11];
			data.useWord = rowData [12];

            return data;
        }


        public override void AddOneIndex(TableItem model)
        {
            if (!cacheOneIndex.ContainsKey(model.category.ToString()))
            {
                cacheOneIndex[model.category.ToString()] = new List<TableItem>();
            }
            cacheOneIndex[model.category.ToString()].Add(model);
        }
    

    }

}
